# ============================================
# 修复 DNF 缓存并安装 Nginx
# ============================================

# 步骤 1: 清理损坏的 DNF 缓存
echo "正在清理损坏的 DNF 缓存..."
sudo rm -rf /var/cache/dnf/*

# 步骤 2: 清理系统临时文件（释放空间）
echo "清理临时文件..."
sudo rm -rf /tmp/pip-* /tmp/pip-build-env-* /tmp/*.log /tmp/*.tmp 2>/dev/null || true

# 步骤 3: 清理系统日志（释放空间）
echo "清理系统日志..."
sudo journalctl --vacuum-time=3d 2>/dev/null || true

# 步骤 4: 检查磁盘空间
echo "检查磁盘空间..."
df -h /

# 步骤 5: 重建 DNF 缓存
echo "重建 DNF 缓存..."
sudo dnf clean all
sudo dnf makecache

# 步骤 6: 安装 Nginx
echo "安装 Nginx..."
sudo dnf install -y nginx

# 步骤 7: 启动并启用 Nginx
echo "启动 Nginx 服务..."
sudo systemctl start nginx
sudo systemctl enable nginx

# 步骤 8: 检查状态
echo "检查 Nginx 状态..."
sudo systemctl status nginx --no-pager | head -n 10

